
/*
 *************************************************************************
 *西瑞克斯研发管理系统
 *版 本: 1.0   
 *日 期：02/08/2012    
 *作 者： 王浩 QQ：873987060   
 *************************************************************************   
 */
package com.application.technical.struts.actions;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.manager.commons.config.ConfigFactory;
import com.manager.commons.page.PageBean;
import com.manager.commons.CurrentUserUtils;
import com.manager.commons.RandomKey;
import com.manager.commons.CommonUtil;
import com.application.attachment.entity.Attachment;
import com.application.attachment.service.AttachmentService;
import com.application.attachment.struts.form.AttachmentForm;
import com.application.role.entity.Role;
import com.application.technical.entity.Technical;
import com.application.technical.struts.form.TechnicalForm;
import com.application.technical.service.TechnicalService;
import com.application.technical.commons.Constants;
import com.application.usertable.entity.Usertable;

/**
 * 
 * Description:TechnicalAction<br />
 * 
 * Version:V0.1<br />
 * 
 * Author: 王浩 QQ：873987060 <br />
 * 
 * History: <br />
 * 
 * 02/08/2012
 * 
 */
public class TechnicalAction extends DispatchAction {

	/**
	 * Service层实例
	 */
	private TechnicalService technicalService;
	private AttachmentService attachmentService;

	/**
	 * 日志
	 */
	private Logger log = Logger.getLogger(this.getClass());

	/**
	 * 实体对象
	 */
	private Technical technical;

	/**
	 * 采用partialList方式分页程序
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public ActionForward getTechnicalPartialList(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("searchTechnical" + "开始");
		TechnicalForm technical = (TechnicalForm) form;
		// 统计总记录数的sql语句
		int resultSize = 0;
		// 初始化pageBean供分页所用
		PageBean pageBean = null;
		// 取得当前页list数据
		List technicalList = null;
		resultSize = technicalService.getAllCountTechnical(technical);
		pageBean = PageBean.getPageBean("technicalTab", resultSize, request);
		technicalList = technicalService.searchTechnical(technical,
				pageBean);
		request.setAttribute("technicalList", technicalList);
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		request.setAttribute("yearSelect", CommonUtil.getYearSelect());
		request.setAttribute("moonSelect", CommonUtil.getMoon());

		log.debug("searchTechnical" + "结束");

		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 到达新增页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toAddTechnical(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("toAddTechnicals");
		Date date = new Date();
		TechnicalForm technicalForm = new TechnicalForm();
		technicalForm.setId(RandomKey.generateID_Long_19());
		technicalForm.setCreatedate(date);
		request.setAttribute("technicalForm", technicalForm);
		request.setAttribute("kg", CommonUtil.getKz());

		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 增加
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward addTechnical(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("addTechnicals");
		Technical technical = this.getTechnical(form);
		technical.setCreatedate(new Date());
		this.technicalService.insertObject(technical);
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 删除
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward deleteTechnical(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("deleteTechnicals");
		TechnicalForm technicalForm = (TechnicalForm) form;
		this.technicalService.deleteTechnicals(technicalForm);
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 到达更新页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toUpdateTechnical(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("toUpdateTechnicals");
		TechnicalForm technicalForm = (TechnicalForm) form;
		technical = (Technical) this.technicalService.searchTechnical(
				technicalForm).get(0);
		request.setAttribute(Constants.DEPARTMENT, technical);
		request.setAttribute("kg", CommonUtil.getKz());
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 更新
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward updateTechnical(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("updateTechnicals");
		Technical technical = this.getTechnical(form);
		technical.setCreatedate(new Date());
		this.technicalService.updateObject(technical);
		
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 查看页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward viewTechnical(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("viewTechnical");
		TechnicalForm technicalForm = (TechnicalForm) form;
		technical = (Technical) this.technicalService.searchTechnical(
				technicalForm).get(0);
		request.setAttribute(Constants.DEPARTMENT, technical);
		request.setAttribute("kg", CommonUtil.getKz());
		return mapping.findForward(Constants.SUCCESS);
	}
	

	// get--set
	/**
	 * @return the TechnicalService
	 */
	public TechnicalService getTechnicalService() {
		return this.technicalService;
	}

	/**
	 * @param TechnicalService
	 *            the TechnicalService to set
	 */
	public void setTechnicalService(TechnicalService technicalService) {
		this.technicalService = technicalService;
	}

	/**
	 * 获取Technical实体
	 * 
	 * @param ActionForm
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 * @return the Technical
	 */
	public Technical getTechnical(ActionForm form)
			throws IllegalAccessException, InvocationTargetException {
		TechnicalForm technicalForm = (TechnicalForm) form;
		technical = new Technical();
		BeanUtils.copyProperties(technical, technicalForm);
		return technical;
	}

	public void setTechnical(Technical technical) {
		this.technical = technical;
	}

	/**
	 * @return the attachmentService
	 */
	public AttachmentService getAttachmentService() {
		return attachmentService;
	}

	/**
	 * @param attachmentService the attachmentService to set
	 */
	public void setAttachmentService(AttachmentService attachmentService) {
		this.attachmentService = attachmentService;
	}

	/**
	 * @return the technical
	 */
	public Technical getTechnical() {
		return technical;
	}


}
